package com.personal.gateway.flinkAllCommand.configurationOption.parameterCheck;

import com.personal.gateway.custom.customException.ConfigurationOptionCheckException;
import com.personal.gateway.flinkAllCommand.configurationOption.ConfigurationOption;
import com.personal.gateway.flinkAllCommand.configurationOption.configurationType.ConfigurationTypeInteger;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

/**
 * @author BigHead
 * @date 2022/1/11 10:57
 * @description ParameterCheckInteger
 */
public class ParameterCheckInteger extends AbstractParameterCheck<Integer, ConfigurationTypeInteger> {


    @Override
    public Integer abstractCheckValue(ConfigurationOption<Integer, ConfigurationTypeInteger> configurationOption, String value) {
        if (StringUtils.isNotEmpty(value)) {
            if (!NumberUtils.isDigits(value)) {
                throw new ConfigurationOptionCheckException(value, configurationOption);
            } else {
                return Integer.valueOf(value);
            }
        }
        return null;
    }
}
